package operator

import (
	"gitee.com/bupt-zkjc/fabric2.2-interface/entity"
)
type BlockOperator struct {
	FabricOperator *FabricOperator
}

func (l *BlockOperator) QueryLatestBlocks(chain entity.Chain, channel entity.Channel) (interface{}, error) {

	fc := entity.ParseFabircChannelWithOrg(chain, channel)
	resp, err := l.FabricOperator.queryLatestBlocks(fc)
	if err != nil {
		logger.Error(err)
		return "Query fail", err
	}
	logger.Info("SDK---Query blocks successful")
	return resp, nil
}

func (l *BlockOperator) QueryBlockByNumber(chain entity.Chain, channel entity.Channel, blockId int) (interface{}, error) {

	fc := entity.ParseFabircChannelWithOrg(chain, channel)
	resp, err := l.FabricOperator.queryBlockByNumber(fc, blockId)
	if err != nil {
		logger.Error(err)
		return "Query fail", err
	}
	logger.Info("SDK---Query block successful")
	return resp, nil
}

func (l *BlockOperator) QueryBlockByHash(chain entity.Chain, channel entity.Channel, blockHash string) (interface{}, error) {

	fc := entity.ParseFabircChannelWithOrg(chain, channel)
	resp, err := l.FabricOperator.queryBlockByHash(fc, blockHash)
	if err != nil {
		logger.Error(err)
		return "Query fail", err
	}
	logger.Info("SDK---Query block successful")
	return resp, nil
}

func (l *BlockOperator) QueryBlockByTxId(chain entity.Chain, channel entity.Channel, txId string) (interface{}, error) {

	fc := entity.ParseFabircChannelWithOrg(chain, channel)
	resp, err := l.FabricOperator.queryBlockByTxId(fc, txId)
	if err != nil {
		logger.Error(err)
		return "Query fail", err
	}
	logger.Info("SDK---Query block successful")
	return resp, nil
}

func (l *BlockOperator) QueryTransactionDetail(chain entity.Chain, channel entity.Channel, txId string) (interface{}, error) {

	fc := entity.ParseFabircChannelWithOrg(chain, channel)
	resp, err := l.FabricOperator.QueryTransactionDetail(fc, txId)
	if err != nil {
		logger.Error(err)
		return "Query fail", err
	}
	logger.Info("SDK---Query Transaction successful")
	return resp, nil
}